package com.icloud.article.boot.controller.app;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.icloud.article.boot.dto.*;
import com.icloud.article.boot.service.ArticleService;
import com.icloud.article.boot.vo.ArticleBrowsedPageVo;
import com.icloud.article.boot.vo.ArticleBrowsedVo;
import com.icloud.article.boot.vo.ArticlePageVo;
import com.icloud.article.boot.vo.ArticleVo;
import com.icloud.common.core.api.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "App帖子接口")
@RequestMapping("/app")
@RequiredArgsConstructor
public class AppArticleController {
    private final ArticleService articleService;

    @ApiOperation("发布帖子")
    @PostMapping("/publish")
    public CommonResult<Boolean> publish(@Validated @RequestBody ArticleDto dto){
        return CommonResult.success(articleService.publish(dto));
    }

    @ApiOperation("删除帖子")
    @DeleteMapping("/delete/{id}")
    public CommonResult<Boolean> delete(@ApiParam("帖子id") @PathVariable("id") Long id){
        return CommonResult.success(articleService.delete(id));
    }

    @ApiOperation("详情")
    @GetMapping("/load")
    public CommonResult<ArticleVo> load(@ApiParam("帖子id") @RequestParam("id") Long id){
        return CommonResult.success(articleService.load(id));
    }

    @ApiOperation("帖子分页")
    @PostMapping("/page")
    public CommonResult<ArticlePageVo> userArticlePage(@Validated @RequestBody ArticlePageDto dto){
        return CommonResult.success(articleService.appPage(dto));
    }

    @ApiOperation("分享帖子")
    @PostMapping("/forward")
    public CommonResult<Boolean> forward(@Validated @RequestBody ForwardDto dto){
        return CommonResult.success(articleService.forward(dto));
    }

    @ApiOperation("取消转发")
    @PostMapping("/forward/cancel")
    public CommonResult<Boolean> cancelForward(@Validated @RequestBody CancelForwardDto dto){
        return CommonResult.success(articleService.cancelForward(dto));
    }
}
